/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import entity.Roles;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author FRANCO
 * @author alberto
 */
@Stateless
public class RolesFacade extends AbstractFacade<Roles> implements RolesFacadeRemote {
    @PersistenceContext(unitName = "socafe-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public RolesFacade() {
        super(Roles.class);
    }

    @Override
    public boolean crearRol(String nombreRol) {
        Roles rol = new Roles(0, nombreRol);
        
        try{
        create(rol);
        return true;
        }catch (Exception ex){ return false;}
    }

    @Override
    public Roles findByName(String nombre) {
      return  (Roles)getEntityManager().createNamedQuery("Roles.findByRol").setParameter("rol", nombre).getSingleResult();
    }
}
